# -*- coding: utf-8 -*- 
import functools
from services.OauthService import FlickrOauthService
from services.DataService import DataServiceFactory
import web

def CheckOAuthDecorator(func):
        """检查是否oauth认证的装饰器 。"""
        @functools.wraps(func)
        def funcWrap(*args, **kwargs):
            if FlickrOauthService.IsAuthenticated():
                return func(*args, **kwargs)
            else:
                web.seeother('/admin/image/oauth',absolute=True)
        return funcWrap

def CheckLoginDecorator(func):
        """检查是否后台登录的装饰器 。"""
        @functools.wraps(func)
        def funcWrap(*args, **kwargs):
            if DataServiceFactory.AdminServiceInstance().logined():
                return func(*args, **kwargs)
            else:
                web.seeother('/admin/login',absolute=True)
        return funcWrap